package com.example.zhaojianxu.signin.common.account.view

import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.util.Log
import android.view.View
import com.example.zhaojianxu.signin.R
import com.example.zhaojianxu.signin.bean.BaseActivity
import com.example.zhaojianxu.signin.common.account.viewModel.AccountViewModel
import com.example.zhaojianxu.signin.common.util.ToastUtil
import kotlinx.android.synthetic.main.activity_logon.*
import kotlinx.android.synthetic.main.common_title_bar.*

/**
 * 注册
 */
class LogonActivity : BaseActivity(), View.OnClickListener {

    private lateinit var mViewModel: AccountViewModel

    override fun initData() {
        mViewModel = ViewModelProviders.of(this)[AccountViewModel::class.java]

        mViewModel.mLogon.observe(this, Observer {
            finish()
        })
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_logon)

    }

    override fun initView() {
        common_title.text = "个人信息"
        common_setting.visibility = View.GONE
        common_back.setOnClickListener(this)
        logon_logon.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when(v?.id){
            R.id.common_back -> {
                finish()
            }
            R.id.logon_logon -> {
                val account = logon_account.text.toString()
                val password = logon_password.text.toString()
                val name = logon_name.text.toString()
                val number = "111" ?: logon_number.text.toString()
                val passwordAgain = logon_password_again.text.toString()

                if (account.isNotEmpty() && password.isNotEmpty() && name.isNotEmpty() && number.isNotEmpty() && passwordAgain.isNotEmpty() && password.equals(passwordAgain)){
                    mViewModel.postLogon(account, password, name, number)
                }else{
                    ToastUtil.instance.showToast(this,"请填写完全！")
                }
            }
        }
    }

}
